package org.liveboardgames.agricola.business.action.processor;

import java.util.List;
import java.util.Map;

import org.liveboardgames.agricola.business.updater.CardUpdater;
import org.liveboardgames.agricola.business.updater.FarmUpdater;
import org.liveboardgames.agricola.domain.Change;
import org.liveboardgames.agricola.domain.Game;
import org.liveboardgames.agricola.domain.action.Action;
import org.liveboardgames.agricola.domain.card.Card;
import org.liveboardgames.agricola.domain.common.Target;
import org.liveboardgames.agricola.domain.player.Player;

public class TakeAllActionProcessor extends ActionProcessor {

  public TakeAllActionProcessor(Game game, Action action, List<Change> changes) {
    super(game, action, changes);
  }

  @Override
  public void execute() {
    Target target = action.getTarget();
    Target link = action.getLink();

    if (target instanceof Player) {
      // Get the card from which to take the resources
      Card card = (Card)link;
      Map<String, Integer> resourcesOnCard = card.getResources();

      // Add the resources to the player
      Player player = (Player)target;
      new FarmUpdater(game, player.getFarm(), changes).addResources(resourcesOnCard);

      // Remove the resources from the card
      new CardUpdater(card, changes).resetResources();
    }
  }

}
